package se.dolkow.skola.datasakerhet.server.storage;

abstract class AbstractDivisionUser implements User {
	private String name;
	private Division division;
	
	public AbstractDivisionUser(String name, Division div) {
		this.name = name;
		this.division = div;
	}
	
	public String getName() {
		return name;
	}
	
	public Division getDivision() {
		return division;
	}
	
	public String toString() {
		return name;
	}

	public final boolean isAuthorized(Action a, Record r) {
		if (a == Action.READ && r.getDivision().equals(division)) {
			return true;
		}
		return isPersonallyAuthorized(a, r);
	}
	
	protected abstract boolean isPersonallyAuthorized(Action a, Record r);
}
